package com.ruoyi.app.controller;

import com.ruoyi.cms.domain.CmsPolicyContent;
import com.ruoyi.cms.service.ICmsPolicyContentService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 政策Controller
 * 
 * @author hct
 * @date 2022-01-22
 */
@RestController
@RequestMapping("/app/public/policycontent")
public class AppPolicyContentController extends BaseController
{
    @Autowired
    private ICmsPolicyContentService cmsPolicyContentService;

    /**
     * 查询政策列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmsPolicyContent cmsPolicyContent)
    {
        startPage();
        List<CmsPolicyContent> list = cmsPolicyContentService.selectCmsPolicyContentList(cmsPolicyContent);
        return getDataTable(list);
    }

    /**
     * 获取政策详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsPolicyContentService.selectCmsPolicyContentById(id));
    }

    /**
     * 新增政策
     */
    @Log(title = "政策", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsPolicyContent cmsPolicyContent)
    {
        return toAjax(cmsPolicyContentService.insertCmsPolicyContent(cmsPolicyContent));
    }

    /**
     * 修改政策
     */
    @PreAuthorize("@ss.hasPermi('cms:policy:edit')")
    @Log(title = "政策", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsPolicyContent cmsPolicyContent)
    {
        return toAjax(cmsPolicyContentService.updateCmsPolicyContent(cmsPolicyContent));
    }

    /**
     * 删除政策
     */
    @PreAuthorize("@ss.hasPermi('cms:policy:remove')")
    @Log(title = "政策", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsPolicyContentService.deleteCmsPolicyContentByIds(ids));
    }

    /**
     * 上架下架信息
     */
    @PreAuthorize("@ss.hasPermi('cms:policy:changMarktable')")
    @Log(title = "政策信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changMarktable")
    public AjaxResult changMarktable(Long id,Integer markTable)
    {
        CmsPolicyContent cmsContent=new CmsPolicyContent();
        cmsContent.setId(id);
        cmsContent.setIsMarketable(markTable);
        return toAjax(cmsPolicyContentService.updateCmsPolicyContent(cmsContent));
    }
}
